﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class CMS_ChatList : System.Web.UI.Page
{
    Usas.Common.Cms.Role ro = new Usas.Common.Cms.Role();
    Usas.Common.Cms.CurrentInfo cinfo = new Usas.Common.Cms.CurrentInfo();
    Usas.BLL.Cms.cmsReview rv = new Usas.BLL.Cms.cmsReview();
    Usas.BLL.Cms.AspPager ap = new Usas.BLL.Cms.AspPager();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            try
            {
                Bind();
            }
            catch
            {
            }
        }
    }

    private void Bind()
    {
        object id = Request["id"];
        object check = Request["check"];
        object name = Request["topic"];
        object IsUrl = Request["IsUrl"];
        int page = 0;
        if (Request["page"] == null)
        {
            page = 1;
        }
        else
        {
            page = Convert.ToInt32(Request["page"].ToString());
        }


        if (ro.GetMd5Str(id.ToString() + "IsUrlTrue") == IsUrl.ToString())
        {
            DataTable dt = null;
            string usasdb = System.Configuration.ConfigurationManager.AppSettings["ConnectionStringUsas"].ToString();
            int count = 0;
            string where = " (Ischeck='0' or Ischeck is null) and ArtId=" + id.ToString();
            string table = " cmsReview as table1 inner join opendatasource('SQLOLEDB','" + usasdb + "').Usasdb.dbo.Employees as table2 on(table1.Reviewer=table2.employeeid)";
            string PK = "ReviewId";
            string cols = "ReviewId,ArtId,Reviewer,Content,EditTime,IsCheck,table2.EmpName";
            string by = "ReviewId";

            dt = ap.ShowListDesc(table, where, PK, 8, page, cols);

            if (dt != null && dt.Rows.Count > 0)
            {
                RptChatList.DataSource = dt;
                RptChatList.DataBind();

                apg.CurrentPageIndex = page;
                apg.PageSize = 8;
                apg.RecordCount = ap.ShowListCount(table, where, PK);


                apg2.CurrentPageIndex = page;
                apg2.PageSize = 8;
                apg2.RecordCount = ap.ShowListCount(table, where, PK);
            }
            else
            {
                DivContent.InnerHtml = "<div style='text-algin:center'>没有评论</div>";
            }
            litTopic.Text = Server.UrlDecode(name.ToString());
        }
    }

    protected void RptChatList_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            DataRowView drv = (DataRowView)e.Item.DataItem;
            LinkButton ldel = (LinkButton)e.Item.FindControl("Del");
            ldel.CommandName = "Del";
            ldel.CommandArgument = drv["ReviewId"].ToString();
            if (cinfo.GetSuperAdminGroup())
            {
                ldel.Visible = true;
            }
            else if (ro.GetMd5Str(Request["id"].ToString() + "checkTrue") == Request["check"].ToString())
            {
                ldel.Visible = true;
            }
            else
            {
                if (drv["Reviewer"].ToString() == cinfo.GetEmpId())
                {
                    ldel.Visible = true;
                }
                else
                {
                    ldel.Visible = false;
                }
            }
        }
    }

    protected void RptChatList_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        if (e.CommandName == "Del")
        {
            rv.Delete(Convert.ToInt32(e.CommandArgument));
            ClientScript.RegisterStartupScript(GetType(), "Msg", "alert('执行成功！');location.href='" + Request.Url.ToString() + "'", true);

        }
    }
}
